package com.example.myapplication.shortvideo.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication.R;
import com.example.myapplication.shortvideo.view.VideoCommentView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: rongfeng
 * @date: 2020/6/17
 * @description
 */
public class VideoCommentAdapter extends RecyclerView.Adapter<BaseCommentView> {
    private List<Object> mCommentList;
    private Context context;


    public VideoCommentAdapter(Context context) {
        this.context = context;
        mCommentList = new ArrayList<>();
    }

    public void addData(List<Object> list){
        mCommentList.addAll(list);
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public BaseCommentView onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new VideoCommentView(getView(R.layout.adapter_video_comment_item, viewGroup));
    }

    @Override
    public void onBindViewHolder(@NonNull BaseCommentView viewHolder, int i) {
        viewHolder.setContent(context, mCommentList.get(i), i);
    }

    @Override
    public int getItemCount() {
        return mCommentList.size();
    }

    private View getView(int layoutId, ViewGroup viewGroup) {
        return LayoutInflater.from(context).inflate(layoutId, viewGroup, false);
    }

}
